<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>添加/修改公告</title>
<%@ include file="/view/common/tags.jsp"%>
	<link rel="stylesheet" href="${sysManagerV1}/js/kindeditor/themes/default/default.css" type="text/css"/>
    <script type="text/javascript" charset="UTF-8" src="${sysManagerV1}/js/kindeditor/kindeditor-min.js"></script>
	<script type="text/javascript" charset="gbk" src="${sysManagerV1}/js/kindeditor/lang/zh_CN.js"></script>
</head>
<body>
	<div class="well well_p" > 
		<sk:form method="post" cssClass="form-horizontal" action="" id="saveAndUpdateFrom" target="_parent"  enctype="multipart/form-data">
			<input type="hidden" id="rowId" name="rowId" value='<%=request.getParameter("rowId")%>'/>
			<input type="hidden" id="isReCommit" value="0">
			<input type="hidden" id="afficheImgPath" name="imgPath" value="">
			<div class="form-group">
				<label class="col-xs-2 text-right">排序编号:</label>
				<div class="col-xs-4">
					<input type="text" class="form-control" name="orderByNo" id="orderByNo" value=""  placeholder="请输入排序编号">
				</div>
			</div>
			<div class="form-group">
				<label class="col-xs-2 text-right">公告标题:</label>
				<div class="col-xs-4">
					<input type="text" class="form-control" name="noticeTitle" id="noticeTitle" value=""  placeholder="请输入公告标题(最多40个字)">
				</div>
			</div>
			<div class="form-group" >
				<label class="col-xs-2 text-right">是否发布:</label>
				<div class="col-xs-4">
					<td colspan="2">
						<label><input name="fbFlag" type="radio" checked="checked"  value="1"/>&nbsp;是</label>&nbsp;&nbsp;&nbsp;&nbsp;
						<label><input name="fbFlag" type="radio"  value="0"/>&nbsp;否</label>
					</td>
				</div>
			</div>
			<div class="form-group" >
				<label class="col-xs-3 text-right">公告图片:</label>
				<div class="cb_box cbx_img_bg col-xs-9">
					<img id="newmainImgPath" src="" width="160px;" height="118px;" onerror="javascript:this.src='${sysManagerV1}/images/uploadImage/noimage.gif';">
					<br/>
					<div class="mainImgPathBox">
						<a href="javascript:;" class="file">选择文件<input id="imgPath" type="file" name="Filedata" onchange="newPic(this,'mainImgPath');"/></a>
					</div>
					<div class="exp_box" style="color:red;">建议尺寸为285*169px(jpg、bmp、png等)，并且小于500KB的图片。</div>
				</div>
			</div>
			<div class="form-group">
				<label class="col-xs-2 text-right">公告内容：</label>
				<div class="col-xs-10">
					<textarea id="noticeContent" name="noticeContent" style="width:570px;height:310px;border:#ccc solid 1px;text-indent:3px;padding-top:3px;"/></textarea>
				</div>
			</div>
		</sk:form>
	</div>
</body>
<%@ include file="/view/common/footer.jsp"%>
<script>
// 提示信息
var msgg='<%=request.getAttribute("msg")%>';
if( msgg && msgg!=null && msgg!='null'){
	layer.msg(msgg);
}

var ke;
var baseAfficheId = $("#rowId").val();
KindEditor.ready(function(K) {
    ke = K.create('textarea[name="noticeContent"]', {
        resizeType : 0,
        urlType : 'domain',
        uploadJson : '${sysManagerV1}/keUploadImg/uploadImg',
        items : [
            'undo', 'redo', '|', 'selectall', 'cut', 'copy', 'paste', 'plainpaste', 'wordpaste', '|',
            'quickformat', 'formatblock', 'fontname', 'fontsize', '|', 'forecolor',  'hilitecolor', 'bold',
            'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'link', 'unlink', 'image', 'emoticons', 'pagebreak',
            '|', 'justifyleft', 'justifycenter',
            'justifyright', 'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'clearhtml', '|', 'preview', 'source', 'about',
        ]
    });
});

$(function(){
    if (CheckUtil.isNotNull(baseAfficheId) && parseInt(baseAfficheId) > 0) {
    }
    //修改公告时获取数据
    if(baseAfficheId > 0){
        $.ajax({
            url: "${sysManagerV1}/pubgBaseAffiche/getBaseAfficheInfo",
            type: "post",
            cache: false,
            data:{"rowId":baseAfficheId},
            dataType:"json",
            async:false,
            success: function(data) {
                if (data == null) {
                    return;
                }
                $("#noticeContent").val(data.noticeContent);
                $("#noticeTitle").val(data.noticeTitle);
                $("#orderByNo").val(data.orderByNo);
                $("input[name='fbFlag']").each(function(){
                    if (data.fbFlag == $(this).val()) {
                        $(this).attr("checked",true);
                    } else {
                        $(this).attr("checked",false);
                    }
                });
                if(data.imgPath != ""){
                    $("#newmainImgPath").attr("src", data.imgPath);
                } else {
                    $("#newmainImgPath").attr("src", "${sysManagerV1}/images/uploadImage/noimage.gif");
                }
                $("#afficheImgPath").val(data.imgPath);
            }
        });
    }
});
var err = {'1':'添加','2':'修改'};
var action = {'1': '${sysManagerV1}/pubgBaseAffiche/save','2':'${sysManagerV1}/pubgBaseAffiche/update'};
function add(){
    var rowId = $('#rowId').val();
    var i;
    if (!CheckUtil.isNotNull(rowId) || rowId <= 0) {
        i = 1;//添加
    } else {
        i = 2;//修改
    }
    var orderByNo = $('#orderByNo').val();
    if (!CheckUtil.isNotNull(orderByNo) || !CheckUtil.isInt(orderByNo, "+") || orderByNo == 0) {
        layer.msg("请输入正确的排序编号!");
        return;
    }
    var noticeTitle = $("#noticeTitle").val();
    if (!CheckUtil.isNotNull(noticeTitle)) {
        layer.msg("请输入公告标题!");
        return;
    }
    if (CheckUtil.isNotNull(noticeTitle) && noticeTitle.length > 40) {
        layer.msg("公告标题不能超过40个字!");
        return;
    }
    var fbFlag =$('input:radio[name="fbFlag"]:checked').val();
    if (!CheckUtil.isNotNull(fbFlag)) {
        layer.msg("请选择是否发布!");
        return;
    }
    var imgPath = $("#imgPath").val();//图片
    if (CheckUtil.isNotNull(imgPath) && !CheckUtil.isImg(imgPath)) {
        layer.msg("上传文件只能为图片!");
        return ;
    }
    //富编辑框内容
    ke.sync();
    if (!CheckUtil.isNotNull(ke.text())) {
        layer.msg("请输入公告内容!");
        return;
    }
    if ($("#isReCommit").val() == 0) {
        $("#isReCommit").val(1);
    }
    //loading层
    var index = layer.load(0, {
        shade: [0.1,'#fff'] //0.1透明度的白色背景
    });

    $.ajax({
        url: action[i],
        type: "post",
        cache: false,
        data: new FormData($("#saveAndUpdateFrom")[0]),
        dataType:"json",
        processData: false,
        contentType: false,
        async:false,
        success: function(data) {
            layer.close(index);
            if(data.code == 0){
                parent.layer.msg("添加成功！");
            } else if(data.code == 1){
                parent.layer.msg("修改成功！");
            } else if(data.code == "-2"){
                parent.window.location.href="${sysManagerV1}/";
            } else {
                parent.layer.msg(data.message);
            }
            if(data.code >= 0){
                parent.findData();
                parent.layer.close(parent.tableIndex);
            }
        }
    });
}
</script>
</html>